package son.hut.vn;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.text.Text;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.ui.activity.SimpleBaseGameActivity;
import org.andengine.util.color.Color;
import android.graphics.Typeface;

public class MainActivity extends SimpleBaseGameActivity {
	public static final int W_CAMERA = 960;
	public static final int H_CAMERA = 640;
	
	private Camera mCamera;
	private Scene scene;
	
	// Default font
	private BitmapTextureAtlas btDefaultFont;
	private Font defaultFont;
	private Text defaultText;
	
	
	
	
	//custom font
	private BitmapTextureAtlas btCustomFont;
	private Font customFont;
	private Text customText;
	
	@Override
 	public EngineOptions onCreateEngineOptions() {
		mCamera = new Camera(0, 0, W_CAMERA, H_CAMERA);
		return new EngineOptions(
				true, 
				ScreenOrientation.LANDSCAPE_FIXED, 
				new RatioResolutionPolicy(W_CAMERA, H_CAMERA), 
				mCamera);
	}

	@Override
	protected void onCreateResources() {
		//load default font
		btDefaultFont = new BitmapTextureAtlas(getTextureManager(), 256, 256);
		defaultFont = new Font(getFontManager(), btDefaultFont, Typeface.DEFAULT_BOLD	, 30, true	, Color.RED);
		btDefaultFont.load();
		defaultFont.load();
		
		//load custom font
		btCustomFont = new BitmapTextureAtlas(getTextureManager(), 256, 256);
		customFont = FontFactory.createFromAsset(
				getFontManager(), 
				btCustomFont, 
				getAssets(), 
				"font/MTCORSVA.TTF", 30, true, 
				android.graphics.Color.BLUE);
		btCustomFont.load();
		customFont.load();
	}
	@Override
	protected Scene onCreateScene() {
		scene = new Scene();
		scene.setBackground(new Background(Color.CYAN));
		
		//dinh nghia text
		defaultText = new Text(100, 50, defaultFont, "Default Font", getVertexBufferObjectManager());
		scene.attachChild(defaultText);
		
		//dinh nghia custom text
		customText = new Text(100, 200, customFont, "Custom Font", getVertexBufferObjectManager());
		scene.attachChild(customText);
		
		return scene;
	}



}
